package main
import (
	"fmt"
	"sort"
	"math/rand"
)

type Person struct {
	Name string
	Age int
}

type StructSlice []Person
func (ss StructSlice) Len() int {
	return len(ss)
}
func (ss StructSlice) Less(i, j int) bool {
	return ss[i].Age < ss[j].Age
}
func (ss StructSlice) Swap(i, j int) {
	ss[i], ss[j] = ss[j], ss[i]
}

func main() {
	var ss StructSlice
	for i:=0;i<10;i++ {
		person := Person{
			Name: fmt.Sprintf("person%d", rand.Intn(100)),
			Age: rand.Intn(100),
		}
		ss = append(ss, person)
	}

	for _, v := range ss {
		fmt.Println(v)
	}
	sort.Sort(ss)
	for _, v := range ss {
		fmt.Println(v)
	}
}